package cn.rkylin.oms.goods.vo;

import java.math.BigDecimal;
import java.util.List;

import org.apache.commons.lang.StringUtils;

import cn.rkylin.oms.goods.domain.Goods;

/**
 * 系统商品值对象，用于满足前台展示、系统间交互的需要
 *
 * @author wangxing
 * @version 1.0.0
 * @created 2017-7-5
 */
public class GoodsVO extends Goods {
    /**
     * 序列化id
     */
    private static final long serialVersionUID = 1197123576331484879L;

    /**
     * 状态定义
     */
    private static final String STATUS_SKUSHOW = "<span class=\"fa fa-chevron-down\" goodsId=\"%s\"></span>";
    private static final String STATUS_CHK = "<input id=\"chkGoods\"   name=\"chkGoods\" type=\"checkbox\" goodsid=\"%s\" /></input>";
    // private static final String STATUS_CHK = "<input id=\"chkGoods\"
    // class=\"chkRule icheck\" style=\"display:none;\" name=\"chkGoods\"
    // type=\"checkbox\" goodsid=\"%s\" /></input>";

    private static final String OPERATION_BTN_EDIT = "<button onclick=\"operationEdit(this,event)\" goodsId=\"%s\" type=\"button\" class=\"btn btn-info btn-xs\"><i class=\"fa fa-edit\"></i>&nbsp;修改</button>";
    private static final String OPERATION_BTN_DELETE = "<button onclick=\"operationDelete(this,event)\" goodsId=\"%s\" type=\"button\" class=\"btn btn-danger btn-xs\"><i class=\"fa fa-trash-o\"></i>&nbsp;删除</button>";

    public void finalize() throws Throwable {
        super.finalize();
    }

    private List<String> listGoodsId;

    public List<String> getListGoodsId() {
        return listGoodsId;
    }

    public void setListGoodsId(List<String> listGoodsId) {
        this.listGoodsId = listGoodsId;
    }

    /**
     * 规格商家编码扩展
     */
    private String skuCode;

    public String getSkuCode() {
        return skuCode;
    }

    public void setSkuCode(String skuCode) {
        this.skuCode = skuCode;
    }

    /**
     * 主数据编码扩展
     */
    private String skuMCode;

    public String getSkuMCode() {
        return skuMCode;
    }

    public void setSkuMCode(String skuMCode) {
        this.skuMCode = skuMCode;
    }

    /**
     * 系统规格名称扩展
     */
    private String skuName;

    public String getSkuName() {
        return skuName;
    }

    public void setSkuName(String skuName) {
        this.skuName = skuName;
    }

    /**
     * 系统规格信息展开按钮扩展
     */
    private String skuShow;

    public String getSkuShow() {
        return String.format(STATUS_SKUSHOW, this.getGoodsId()).toString();
    }

    public void setSkuShow(String skuShow) {
        this.skuShow = String.format(STATUS_SKUSHOW, "").toString();
    }

    /**
     * 系统商品复选框扩展
     */
    private String chk;

    // public String getChk() {
    // return String.format(STATUS_CHK, this.chk).toString();
    // }
    public String getChk() {
        return String.format(STATUS_CHK, this.getGoodsId()).toString();
    }

    public void setChk(String chk) {
        this.chk = "";
    }

    /**
     * 修改、删除按钮扩展
     */
    private String operation;

    public String getOperation() {
        StringBuffer opButton = new StringBuffer();
        if (StringUtils.isNotEmpty(getGoodsId())) {
//            if (!"51f17f6ddbae11e68c4d001e67c7ec3a".equals(this.getEntId())){
//                opButton.append(String.format(OPERATION_BTN_EDIT, getGoodsId()));
//                opButton.append("&nbsp;");
//            }
            opButton.append(String.format(OPERATION_BTN_EDIT, getGoodsId()));
            opButton.append("&nbsp;");
            opButton.append(String.format(OPERATION_BTN_DELETE, getGoodsId()));
        }
        operation = opButton.toString();
        return operation;
    }

    public void setOperation(String operation) {
        this.operation = operation;
    }

    /**
     * orderBy子句
     */
    private String orderBy;

    public String getOrderBy() {
        // 此字段需要防止sql注入
        return orderBy == null ? null : orderBy.replaceAll(".*([';]+|(--)+).*", " ");
    }

    public void setOrderBy(String orderBy) {
        this.orderBy = orderBy;
    }

    /**
     * 搜索条件
     */
    private String searchCondition;

    public String getSearchCondition() {
        return searchCondition;
    }

    public void setSearchCondition(String searchCondition) {
        this.searchCondition = searchCondition;
    }

    // 以下是SKU相关扩展信息----------------------------------------------------------
    /**
     * 标准售价
     */
    private BigDecimal salePrice;
    /**
     * 成本价
     */
    private BigDecimal costPrice;
    /**
     * 允许赠品
     */
    private String giftsYn;
    /**
     * 虚拟商品
     */
    private String virtYn;
    /**
     * 规格条码
     */
    private String barCode;

    /**
     * 项目id
     */
    private String prjId;

    public String getPrjId() {
        return prjId;
    }

    public void setPrjId(String prjId) {
        this.prjId = prjId;
    }

    public BigDecimal getSalePrice() {
        return salePrice;
    }

    public void setSalePrice(BigDecimal salePrice) {
        this.salePrice = salePrice;
    }

    public BigDecimal getCostPrice() {
        return costPrice;
    }

    public void setCostPrice(BigDecimal costPrice) {
        this.costPrice = costPrice;
    }

    public String getGiftsYn() {
        return giftsYn;
    }

    public void setGiftsYn(String giftsYn) {
        this.giftsYn = giftsYn;
    }

    public String getVirtYn() {
        return virtYn;
    }

    public void setVirtYn(String virtYn) {
        this.virtYn = virtYn;
    }

    public String getBarCode() {
        return barCode;
    }

    public void setBarCode(String barCode) {
        this.barCode = barCode;
    }

}